package codigos;

import java.security.MessageDigest;

public class Seguridad {
    public static String cifradoMD5(String clear) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] b = md.digest(clear.getBytes());
        int size = b.length;
        StringBuilder h = new StringBuilder(size);
        //algoritmo y arreglo md5
        for (int i = 0; i < size; i++) {
            int u = b[i] & 255;
                if (u < 16) {
                    h.append("0").append(Integer.toHexString(u));
                }
            else {
                    h.append(Integer.toHexString(u));
            }
        }
        //clave encriptada
        //System.out.println(h.toString());
        return h.toString();
    }
}
